Skip to content

fix: stop prefetches going untracked and old feed lists passing as fresh, and three smaller fixes - #341

Merged
therealsama merged 6 commits into
mainfrom
fix/prefetch-restart-feed-cache-poll-options-404-csp
Nov 22, 2026
Merged

therealsama merged 6 commits into
mainfrom
fix/prefetch-restart-feed-cache-poll-options-404-csp

Conversation

@therealsama

@therealsama therealsama commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes four bugs found in a review of the codebase and two layout bugs found while checking the new poll-option notice, and documents one design choice. Each commit passes typecheck, lint and the unit tests on its own.

Bug fixes

  • A story's comments could be prefetched twice, and the prefetch could no longer be stopped. A story card prefetches its comments while it is in view and aborts the prefetch when it scrolls out. Scrolled back in before the aborted prefetch settled, the card started a new one, and the aborted one's cleanup then dropped the new one from the tracked prefetches. The new prefetch could no longer be aborted, didn't count toward the limit of three at a time, and the card's next return fetched the comments again while it was still running. A prefetch's cleanup now removes the entry only if it is still its own.
  • Opening a story from the list view made the feed's old list look freshly fetched to the swipe view. Saving the feed's session wrote its list back to the cache stamped with the current time, so for five minutes a list fetched hours earlier passed as fresh. Only the swipe view reads that freshness: its background section prefetching skipped the feed instead of refreshing it, and it opened the feed on the old list's first story instead of waiting for the refresh. The list view refreshes a cached list every time it opens, so this showed only when one browser switched layouts within those five minutes, such as a phone turned to landscape (the list view starts at 768px wide) and back. Saving the session now keeps the list's fetch time.
  • A link to a poll option opened an empty story page. A Hacker News poll option is an item with text and a score but no title. Read as a story, it showed an empty heading, the tab titled "HackerTok", and "No comments yet." The item page and the swipe view now say poll options aren't supported, and title the tab after that notice. A poll option also no longer fetches comments it can't have: its page read the item again, searched Algolia for comments, and held background prefetches until both answered. Polls still show like Ask posts: title, text and comments, without their options. Polls are rare now (about one a week over the past year) and only appear in the Firebase-backed feeds.
  • 404.html had no Content-Security-Policy. GitHub Pages serves it for every unknown path, and its inline script redirects the path into the app's hash route. Vite copied it from public/ as is, so the CSP plugin never saw it. It is now a build entry beside index.html, so its inline script is hashed into a CSP meta tag like the app's.
  • On the phone, a swipe panel's states sat under the header instead of in the middle of the screen. This covers the poll-option notice, an item's not-found and error states, a comment's error and deleted states, and the end-of-feed error. Their wrapper asked for min-height: 100%, but the active swipe panel only has a min-height, so the percentage resolved to nothing. Such a state also jumped up when a swipe landed on it, because the peeking panel it came from has a fixed height. It now fills the panel between the header and the offline bar. Desktop was already centered.
  • The empty illustration's rising dots sat 2px left of the box's middle. Every empty state uses it, such as "No comments yet", "No replies yet", the poll-option notice, and an empty submissions list for a user or a domain. The dots now rise from the center.

The Top feed shows HN's current front page, then each earlier UTC day's front page from Algolia, so today's stories ranked 21 and below are never shown. That is by design, and a comment now says so.

Known limitations

  • The poll-option notice doesn't link to its poll, because StoryItem has no field for the parent poll.
  • Polls show without their options or vote counts, so a poll's text may refer to choices that aren't shown.

Testing

  • npm run typecheck: passed
  • npm run lint: passed
  • npm run test:run: passed, 1199 tests in 64 files
  • git rebase -x 'npm run typecheck && npm run lint && npx vitest run' main: every commit passed on its own
  • npx playwright test --project=chromium --project="Mobile Chrome" --reporter=line --retries=0: 469 passed, 9 skipped. Its web server runs npm run build, which passed.
  • Not run: the Firefox and Mobile Safari Playwright projects, because only Chromium is installed locally.
  • Each new test fails with its fix reverted.
  • Checked by hand on the dev server, on desktop and in phone emulation (390×844, touch): polls 126809 and 48322267 show as stories with their comments, and poll option 126810 shows the notice, with the tab titled "Poll options aren't supported | HackerTok" and no comments search. On the phone the notice now has about 262px above and below it, also mid-swipe and after a swipe lands. On desktop it is unchanged, at 147px above and 149px below.

… view

A story card prefetches its comments while it is in view and aborts the
prefetch when it scrolls out. Scrolled back in before the aborted
prefetch settled, the card started a new one, and the aborted one's
cleanup then dropped the new one from the tracked prefetches. The
untracked prefetch could no longer be aborted, didn't count toward the
limit of three at a time, and the card's next return fetched the
comments again while it was still running.

A prefetch's cleanup now removes the entry only if it is still its own.
Opening a story from the list view saves the feed's session, and wrote
the feed's list back to the cache stamped with the current time. A list
fetched hours earlier then passed as just fetched for five minutes.

Only the swipe view reads that freshness. In that time its background
section prefetching skipped the feed instead of refreshing it, and it
opened the feed on the old list's first story instead of waiting for the
refresh. The list view refreshes a cached list every time it opens, so
this showed only when one browser switched layouts within those five
minutes, such as a phone turned to landscape and back.

Saving the session now keeps the list's fetch time, and skips the write
when the list has no cache entry: it is over a day old, or storage failed.
The Top feed is HN's current front page, then each earlier UTC day's
front page from Algolia. Today's stories ranked 21 and below are never
shown. That is by design, so say so where the feed moves on to yesterday.
A Hacker News poll option is an item of its own, with text and a score
but no title. Read as a story, a link to one opened a page with an empty
heading, the tab titled "HackerTok" and "No comments yet." The page also
read the item again and searched Algolia for comments a poll option
can't have, and held background prefetches until both answered.

A poll option now keeps its type. The item page and the swipe view say
poll options aren't supported, and title the tab after that notice. It
fetches only the item, as a comment item does. A copy cached as a story
before this change is corrected by the revalidation, whose type wins.

Polls themselves still show like Ask posts: title, text and comments,
without the options.
GitHub Pages serves 404.html for any path it has no file for, and its
inline script redirects the path into the app's hash route. Vite copies
public/ as is, so the build's CSP plugin never saw 404.html, and the
page shipped with no CSP while every other page has one.

404.html is now a build entry beside index.html, so the plugin hashes
its inline script into a CSP meta tag, and an e2e test checks it.
On the phone, a state shown in place of a swipe panel's content sat right
under the header instead of in the middle of the screen. Its wrapper asked
for `min-height: 100%`, but the active panel only has a min-height, so the
percentage resolved to nothing. The state also jumped up when a swipe
landed on it, because the peeking panel it came from has a definite height.

The new `.full-screen-state` takes the panel's box under the header and
above the offline bar. This covers the poll-option notice, the item's
not-found and error states, the comment's error and deleted states, and
the end-of-feed error.

The empty illustration's rising dots also sat 2px left of the box's
middle, on every layout. They now rise from its center, under "No
comments yet" and the poll-option notice alike.
@therealsama
therealsama force-pushed the fix/prefetch-restart-feed-cache-poll-options-404-csp branch from f5c0f31 to 4626092 Compare November 22, 2026 18:10
@therealsama therealsama changed the title fix: stop prefetches going untracked and old feed lists passing as fresh, and two smaller fixes fix: stop prefetches going untracked and old feed lists passing as fresh, and three smaller fixes Nov 22, 2026
@therealsama
therealsama merged commit a5a9b86 into main Nov 22, 2026
4 checks passed
@therealsama
therealsama deleted the fix/prefetch-restart-feed-cache-poll-options-404-csp branch November 22, 2026 19:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants